package org.boyan.query;

import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.Sheet;
import org.boyan.entity.query.ClusterTable;
import org.boyan.entity.query.StrutDevise;

import java.util.List;


public class ExcelToStrutDevise {

    //将excel文件解析成支撑设计需要信息的类
    public static StrutDevise getStrutDevise(Sheet sheet){
        StrutDevise strutDevise=new StrutDevise();
        try{
            List<ClusterTable> clusterTableList=ExcelToClusterTable.getClusterTableList(sheet);
            strutDevise.setClusterTableList(clusterTableList);
            strutDevise.setClusterTableName(sheet.getRow(1).getCell(4).getStringCellValue());
            strutDevise.setRowkeyRule(sheet.getRow(1).getCell(5).getStringCellValue());
            CellType dataVolumnCellType=sheet.getRow(1).getCell(6).getCellType();
            String dataVolumn;
            if(dataVolumnCellType==CellType.NUMERIC){
                dataVolumn=String.valueOf(sheet.getRow(1).getCell(6).getNumericCellValue());
            }else{
                dataVolumn=sheet.getRow(1).getCell(6).getStringCellValue();
            }
            strutDevise.setDataVolume(dataVolumn);
            CellType dataGrowthCellType=sheet.getRow(1).getCell(7).getCellType();
            String dataGrowth;
            if(dataGrowthCellType==CellType.NUMERIC){
                dataGrowth=String.valueOf(sheet.getRow(1).getCell(7).getNumericCellValue());
            }else{
                dataGrowth=sheet.getRow(1).getCell(7).getStringCellValue();
            }
            strutDevise.setDataGrowth(dataGrowth);
        }catch (Exception e){
            e.printStackTrace();
        }
        return strutDevise;
    }
}
